package controller.impl;

import com.google.gson.Gson;
import controller.AnalysisResult;
import model.JsonResult;
import model.Result;
import net.sf.json.JSONArray;

import java.util.ArrayList;
import java.util.List;

public class AnalysisResultImpl implements AnalysisResult {

    public boolean isGetMsgSuccess(String getJson) {

        Gson gson = new Gson();
        JsonResult jsonResult = gson.fromJson(getJson, JsonResult.class);
        String msg = jsonResult.getMsg();

        if ("执行成功！".equals(msg)) {
            List results = new ArrayList<Result>();
            results = jsonResult.getResult();
            return results.size() != 0;
        } else {
            return false;
        }
    }

    public String getResultMsg(String getJson) {
        Gson gson = new Gson();
        JsonResult jsonResult = gson.fromJson(getJson, JsonResult.class);
        JSONArray jsonArray = JSONArray.fromObject(jsonResult.getResult());
        String result = jsonArray.toString();
        return result.substring(1, result.length() - 1);
    }

}
